home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / haeberli / tools / resglue.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  3KB  |  108 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include "stdio.h"
  18.  
  19. #define BACKMAGIC    (('P'<<24)+('A'<<16)+('U'<<8)+('L'<<8))
  20. #define MAXRES        (100)
  21.  
  22. char nametab[MAXRES][32];
  23. int offsettab[MAXRES];
  24. int lengthtab[MAXRES];
  25.  
  26. main(argc,argv)
  27. int argc;
  28. char **argv;
  29. {
  30.     int i, n, pos;
  31.     FILE *outf, *inf;
  32.     long magic;
  33.     char cmd[256];
  34.  
  35.     if(argc<4) {
  36.     fprintf(stderr,"usage: resglue progin progout files . . . . \n");
  37.     exit(1);
  38.     }
  39.     outf = fopen("/usr/tmp/XXXX.resglue","w");
  40.     if(!outf) {
  41.     fprintf(stderr,"resglue: can't open output file for writing\n");
  42.     exit(1);
  43.     }
  44.     inf = fopen(argv[1],"r");
  45.     if(!inf) {
  46.     fprintf(stderr,"resglue: can't open input file %s for reading\n",argv[1]);
  47.     exit(1);
  48.     }
  49.     pos = fcopy(inf,outf);
  50.     fclose(inf);
  51.     n = 0;
  52.     for(i=3; i<argc; i++) {
  53.     offsettab[n] = pos;
  54.     strcpy(nametab[n],argv[i]);
  55.     inf = fopen(argv[i],"r");
  56.     if(!inf) {
  57.         fprintf(stderr,"resglue: can't open input file %s for append\n",argv[i]);
  58.         exit(1);
  59.     }
  60.     lengthtab[n] = fcopy(inf,outf);
  61.     pos += lengthtab[n];
  62.     close(inf);
  63.     n++;
  64.     if(n == MAXRES) {
  65.         fprintf(stderr,"resglue: max resource files is %d for now\n",MAXRES);
  66.         exit(1);
  67.     }
  68.     }
  69.     for(i=0; i<n; i++) {
  70.     fwrite(nametab[i],32,1,outf);
  71.     fwrite(&offsettab[i],sizeof(long),1,outf);
  72.     fwrite(&lengthtab[i],sizeof(long),1,outf);
  73.     }
  74.     fwrite(&n,sizeof(long),1,outf);
  75.     magic = BACKMAGIC;
  76.     fwrite(&magic,sizeof(long),1,outf);
  77.     fwrite(&magic,sizeof(long),1,outf);
  78.     fwrite(&magic,sizeof(long),1,outf);
  79.     if(ferror(outf)) {
  80.     fprintf(stderr,"resglue: error writing file\n");
  81.     exit(1);
  82.     }
  83.     fclose(outf);
  84.     sprintf(cmd,"mv /usr/tmp/XXXX.resglue %s",argv[2]);
  85.     system(cmd);
  86.     sprintf(cmd,"chmod +x %s",argv[2]);
  87.     system(cmd);
  88. }
  89.  
  90.  
  91. int fcopy(inf,outf)
  92. FILE *inf, *outf;
  93. {
  94.     char tmpbuf[10240];
  95.     int nbytes, totbytes;
  96.  
  97.     totbytes = 0;
  98.     while(1) {
  99.         nbytes = fread(tmpbuf,1,10240,inf);
  100.         if(nbytes<=0)
  101.             break;
  102.         fwrite(tmpbuf,1,nbytes,outf);
  103.         totbytes += nbytes;
  104.     }
  105.     return totbytes;
  106. }
  107.  
  108.